# Maintainer: Andrew Leech <andrew@alelec.net>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=libusb-compat
pkgbase="mingw-w64-${_realname}-git"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=r76.b5db9d0
pkgrel=2
pkgdesc="Allows applications written for libusb-0.1 to work with libusb-1.0 (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://libusb.info/"
license=('spdx:LGPL-2.1-or-later')
depends=(${MINGW_PACKAGE_PREFIX}-libusb)
options=('staticlibs')
makedepends=("git"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
_commit="b5db9d0"
source=("${_realname}::git+https://github.com/libusb/libusb-compat-0.1.git#commit=${_commit}")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(git rev-list --count "${_commit}")" "$(git rev-parse --short "${_commit}")"
}

prepare() {
  cd "${srcdir}/${_realname}"

  ./bootstrap.sh
}

build() {
  [[ -d ${srcdir}/build-${CARCH} ]] && rm -rf ${srcdir}/build-${CARCH}
  mkdir -p ${srcdir}/build-${CARCH} && cd ${srcdir}/build-${CARCH}

  ../${_realname}/configure \
      --prefix=${MINGW_PREFIX} \
      --{host,build}=${MINGW_CHOST} \
      --includedir=${MINGW_PREFIX}/include/libusb-compat \
      --disable-dependency-tracking \
      --enable-static \
      --enable-shared

  make
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR="${pkgdir}" install
}
